package com.chwn.curiousdiary.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.chwn.curiousdiary.ui.main.MainActivity;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Myshikin on 2017/4/5.
 */

public class JPushReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        String action = intent.getAction();
        String s = "cn.jpush.android.intent.NOTIFICATION_RECEIVED";
        String actionNotificationOpened = JPushInterface.ACTION_NOTIFICATION_OPENED;
        String actionRegistrationId = JPushInterface.ACTION_REGISTRATION_ID;
        String ACTION_NOTIFICATION_RECEIVED = JPushInterface.ACTION_NOTIFICATION_RECEIVED;
        String ACTION_RICHPUSH_CALLBACK = JPushInterface.ACTION_RICHPUSH_CALLBACK;
        String ACTION_CONNECTION_CHANGE = JPushInterface.ACTION_CONNECTION_CHANGE;


        /*Intent notifyIntent = new Intent(context, SplashActivity.class);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(notifyIntent);*/

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(action)) {
            String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(action)) {


        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
            Intent i = new Intent(context, MainActivity.class);
            //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(i);
        } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(action)) {
        } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(action)) {
        } else {
        }
    }
}
